package com.happe.foodeasy.controller.index;

import com.alibaba.fastjson.JSON;
import com.happe.foodeasy.dto.CommodityBaseDTO;
import com.happe.foodeasy.dto.CommodityTypeDTO;
import com.happe.foodeasy.dto.PageInfoDto;
import com.happe.foodeasy.manage.commodity.entity.CommodityStatusEntity;
import com.happe.foodeasy.service.CommodityService;
import com.happe.foodeasy.util.CommodityStateEnum;
import com.happe.foodeasy.util.ResultEntity;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/indexCommodity")
public class IndexCommodityController {
    @Resource
    private CommodityService commodityService;

    /**
     * 获得所有的商品类型
     *
     * @return 使用ResultEntity包裹的商品类型的列表
     */
    @RequestMapping(path = "/retrieveAllCommodityType", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody()
    public String retrieveAllCommodityType() {
        List<CommodityTypeDTO> allType = commodityService.selectAllCommodityType();
        return JSON.toJSONString(new ResultEntity(allType));
    }

    /**
     * 该mapping用于获得商品的基本信息
     *
     * @param commodityTypeId 商品的类型id
     * @param pageInfoDto     分页信息
     */
    @RequestMapping("/baseInfo")
    public void retrieveBaseInfo(long commodityTypeId, PageInfoDto pageInfoDto) {
        long totalCount = commodityService.selectTotalCountByParam(commodityTypeId, CommodityStateEnum.ON_SHELF.value());
        List<CommodityBaseDTO> allCommodityBaseInfo = commodityService.selectTargetCommodityByParam(commodityTypeId, pageInfoDto);
    }
}
